package com.lmy.springboot_rabbitmq.service.topic;

import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.*;
import org.springframework.stereotype.Service;

/**
 * Email接收消息服务
 * @RabbitListener 注解用于监听指定队列，完成消息接收
 * @RabbitHandler 注解用于标识一个方法，该方法用来处理从队列中接收到的消息。
 * 可以使用@RabbitHandler处理多种参数类型的消息，只需在形参中指定参数类型，如String 接收 String类型的消息 Integer接收 Integer类型的消息
 * 在@RabbitListener 注解中可以建立绑定关系和创建队列、交换机，这样就可以不用写配置类
 */
@Service
@RabbitListener(bindings = @QueueBinding(
        value = @Queue(value = "email_topic_queue", durable = "true", autoDelete = "false"),
        exchange = @Exchange(value = "topic_order_exchange", type = ExchangeTypes.TOPIC),
        key = "#.email.#"
))
public class TopicEmailConsumerService {

    @RabbitHandler
    public void receiveMessage(String message) {
        System.out.println("email_topic_queue--接收到了订单信息:" + message);
    }
}
